﻿#region using statements

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using NGen;
using NGen.Managers.Collision;
using NGen.Managers.GameObject;
using NGen.Managers.Input;

using Nuclex.Input;

#endregion

namespace XNAGameDemo.GameObjects
{
	internal class MouseBall : GameObject2D, ICollidable2D, IMouseListener
	{
		private BoundingBox m_boundingBox;

		#region IMouseListener Members

		public void MousePressed(MouseButtons p_button) {}

		public void MouseReleased(MouseButtons p_button) {}

		public void MouseMoved(float p_x, float p_y) {
			m_position.X = p_x;
			m_position.Y = p_y;
		}

		public void MouseWheelScroll(float p_ticks) {}

		#endregion

		protected override void _Initialize() {
			base._Initialize();
			m_texture = GameEngine.GameContent.Load<Texture2D>("Content\\Textures\\baseball");

			m_scale.X = 0.25f;
			m_scale.Y = 0.25f;

			m_origin.X = m_texture.Width * m_scale.X / 2.0f;
			m_origin.Y = m_texture.Height * m_scale.Y / 2.0f;
			
			m_boundingBox = new BoundingBox(new Vector3(), new Vector3(m_texture.Width * m_scale.X, m_texture.Height * m_scale.Y, 1.0f));

			m_textureTint = Color.WhiteSmoke;

			GameEngine.GetService<IManagerCollision2D>().RegisterCollidable(Id, false);
			GameEngine.GetService<IManagerInput>().AddMouseListener(this);
		}

		protected override void _Cleanup() {
			base._Cleanup();
			GameEngine.GetService<IManagerCollision2D>().UnRegisterCollidable(Id);
			GameEngine.GetService<IManagerInput>().RemoveMouseListener(this);
			GameEngine.GetService<Game>().IsMouseVisible = true;
		}

		protected override void _Update(GameTime p_gameTime) {
			m_zDepth = 1 - (m_position.Y / GameEngine.GameWindow.ClientBounds.Height + .001f);
		}

		#region ICollidable implementation

		public BoundingBox BoundingBox {
			get { return m_boundingBox; }
			set { m_boundingBox = value; }
		}

		public void Collided(CollisionMessage2D p_objectCollidedWith) {}

		#endregion
	}
}